﻿namespace Samples
{
    public interface IMyInterface
    {
        string Name { get; set; }
        int Price { get; set; }
    }

    public enum MyEnum : long
    {
        First,
        Second
    }

    public class BinarySearch
    {
        public event Action<string, int> SearchAction1;

        public event Action<double, decimal> SearchAction2;

        public static int BinarySearchIterative(int[] array, int target)
        {
            int left = 0;
            int right = array.Length - 1;

            while (left <= right)
            {
                int mid = left + (right - left) / 2;

                if (array[mid] == target)
                    return mid;

                if (array[mid] < target)
                    left = mid + 1;
                else
                    right = mid - 1;
            }

            return -1; // Element not found
        }

        public static void Main()
        {
            int[] array = { 2, 5, 8, 12, 16, 23, 38, 56, 72, 91 };
            int target = 23;

            int result = BinarySearchIterative(array, target);

            if (result == -1)
                Console.WriteLine("Element not found in the array");
            else
                Console.WriteLine("Element found at index " + result);
        }

        public static void LocalScope()
        {
            try
            {
                for (int i = 0; i < 10; i++)
                    Console.WriteLine(i);
                for (int i = 10; i < 20; i++)
                    Console.WriteLine(i);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("finally");
            }
        }
    }
}